package com.github.ki4so.sso.dto;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.StringUtils;

/**
 * 登录凭据dto
 * @author TR1
 *
 */
@XmlRootElement
public class CredentialDto implements Serializable {

	private static final long serialVersionUID = -2780258105288890287L;

	/*用户登录账号*/
	private String username;

	/*用户登录密码*/
	private String password;

	/*短信、邮件快捷登录验证码*/
	private String validteCode;

	/*登录类型*/
	private LoginType loginType;

	private String appId;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getValidteCode() {
		return validteCode;
	}

	public void setValidteCode(String validteCode) {
		this.validteCode = validteCode;
	}

	public LoginType getLoginType() {
		return loginType;
	}

	public void setLoginType(LoginType loginType) {
		this.loginType = loginType;
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}
	
	/**
	 * 输入参数的有效性校验
	 * @return true 有效， false 无效
	 */
	public boolean isValid() {
		if (StringUtils.isBlank(username)) {
			return false;
		}
		if (loginType == null) {
			return false;
		}
		if (loginType == LoginType.SMS_QUICK_LOGIN || loginType == LoginType.MAIL_QUICK_LOGIN) {
			if (StringUtils.isBlank(validteCode)) {
				return false;
			}
			return true;
		}
		if (StringUtils.isBlank(password)) {
			return false;
		}
		return true;
	}

}
